package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import liumengbaio.lolzhangyoubao.R;

/**
 * 英雄时刻页面
 * Created by lanouhn on 16/9/3.
 */
public class MoreHeroMomentActivity extends AppCompatActivity {
    private WebView mWebView;
    private String url = "http://qt.qq.com/php_cgi/lol_mobile/hero_time/tpl/navigation.html";
    private TextView back;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.more_heromoment);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        mWebView = (WebView) findViewById(R.id.more_webView);
        back = (TextView) findViewById(R.id.more_back);
    }


    //设置WebView的url链接
    private void initData() {
        WebSettings mWebSettings = mWebView.getSettings();
        mWebSettings.setJavaScriptEnabled(true);

        //打开页面，不调用系统浏览器
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        mWebView.loadUrl(url);
    }

    private void initEvent() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    //按返回键，是返回上一页面 而不是关闭页面
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
            mWebView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
